import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: null ,  //用户信息
    collapse: false,  //折叠
    //菜单数据
    userMenus: [
      {
        name: "边框样式",
        component: () => import("../views/layout/Index.vue"),
        path: "/",
        icon: 'el-icon-myshouye',
        children: [{
          name: "首页",
          component: () => import("../views/home/Home.vue"),
          path: "/home",
          icon: 'el-icon-myshouye',
        }]
      },
      {
        name: "测试一",
        component: () => import("../views/layout/Index.vue"),
        path: "/test1",
        icon: 'el-icon-myshouye',
        children: [{
          name: "测试1.1",
          component: () => import("../views/home/Home.vue"),
          path: "/test11",
          icon: 'el-icon-myshouye',
        }]
      },
      {
        name: "测试二",
        component: () => import("../views/layout/Index.vue"),
        path: "/test2",
        icon: 'el-icon-myshouye',
        children: [{
          name: "测试2.2",
          component: () => import("../views/home/Home.vue"),
          path: "/test22",
          icon: 'el-icon-myshouye',
        }]
      },
      {
        name: "测试三",
        component: () => import("../views/layout/Index.vue"),
        path: "/test3",
        icon: 'el-icon-myshouye',
        children: [{
          name: "首页",
          component: () => import("../views/home/Home.vue"),
          path: "/test33",
          icon: 'el-icon-myshouye',
        }]
      },
      {
        name: "测试四",
        component: () => import("../views/layout/Index.vue"),
        path: "/test4",
        icon: 'el-icon-myshouye',
        children: [{
          name: "首页",
          component: () => import("../views/home/Home.vue"),
          path: "/test44",
          icon: 'el-icon-myshouye',
        }]
      }
    ],
    tabList: [],   //标签页列表
  },
  getters: {
  },
  mutations: {
    login(state, user) {
      console.log("传过来信息：", user)
      console.log("模拟一个token.....")
      user.token = "xxxxxxxxxxxxxxxxxxxxxx"
      user.avatar = "src/assets/images/好看1.jpg"
      sessionStorage.setItem('token', user.token)
      state.userInfo = user
    },
    saveTab(state, tab) {
      if (state.tabList.findIndex((item) => item.path === tab.path) == -1) {
        state.tabList.push({ name: tab.name, path: tab.path })
      }
    },
  },
  actions: {
  },
  modules: {
  },
  plugins: [
      createPersistedState({
        storage: window.sessionStorage
      })
  ]
})
